package cn.uo86.mail.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class md5test {
	private static String hexits = "0123456789abcdef";

	private static byte[] Md5f(String plainText) {
		byte[] ab = new byte[16];
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.update(plainText.getBytes());
			byte b[] = md.digest();
			ab = b;
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return ab;
	}

	public md5test() {
	}

	private static String toHex(byte block[]) {
		StringBuffer buf = new StringBuffer();
		for (int i = 0; i < block.length; i++) {
			buf.append(hexits.charAt(block[i] >>> 4 & 0xf));
			buf.append(hexits.charAt(block[i] & 0xf));
		}
		return String.valueOf(String.valueOf(buf));
	}

	public static void main(String[] args) {

		md5test mt = new md5test();
		String indata = args[0];
		char[] bs1;
		byte[] mp = mt.Md5f(indata);

		Base64 bs = new Base64();
		bs1 = bs.encode(mp);
		String bt = toHex(mp);
		System.out.println("The Hex number of MD5 is: " + bt);
		System.out.print("The Base64 change of MD5 is: {MD5}");
		System.out.println(bs1);
	}

}
